-- SkyElemMine
-- create by huanghr May/25/2016

-- 初始化
function initSkyElemMine(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();


            local function okFunc()
                local elementId = self.gridData.element;
                local args = DungeonM.queryElement(elementId).args;
                local eventCost = args.cost;

                if eventCost[1] == 1 and ItemM.getAmount(ME.user, eventCost[2]) < eventCost[3] then
                    alert(getLocStr("lack_spade"));
                    return;
                end

                local pos = self.gridData:getPos();
                DungeonActionM.go("do_building_bonus", pos);
            end
            self:openBuildingView(okFunc);
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
end